using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PlayerLoop;

[Serializable]
[PlayerStateScript(EPlayerState.Fall)]
public class PlayerFallState : PlayerStateBase
{
    private static readonly int IsFalling = Animator.StringToHash("isFalling");

    public override void Update()
    {
        base.Update();

        if(stateMachine.IsTouchingGround)
            stateMachine.SetState(EPlayerState.Idle);
    }

    public override void FixedUpdate()
    {
        FallMove();
    }

    public override void EnterState()
    {
        // Debug.Log("Fall");
        stateMachine.playerComponentContex.animator.SetBool(IsFalling,true);
    }

    public override void ExitState()
    {
        // Debug.Log("Exit");
        stateMachine.playerComponentContex.animator.SetBool(IsFalling,false);
    }

    public override void HandleInput(EPlayerInput playerInput, EInputType inputType)
    {
        
    }

    private void FallMove()
    {
        var velocity = new Vector2(stateMachine.playerInputDirction.x  * stateMachine.fallingMoveSpeed,stateMachine.playerComponentContex.rigidbody.velocity.y);
        stateMachine.playerComponentContex.rigidbody.velocity = velocity;
    }

    public PlayerFallState(PlayerStateMachine sm) : base(sm)
    {
    }
}
